<?php


function list_jabatan(){
	$header = array(
		'#'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'No Organisasi '=>array('style'=>'border-bottom:2px solid;width:15%'),  
		'Jabatan'=>array('style'=>'border-bottom:2px solid;width:35%'),  
		'Posisi Kosong'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'Banyak Pelamar'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		' '=>array('style'=>'border-bottom:2px solid;width:10%'),
	);
	$i = 0;
	$query = "SELECT a.* FROM jabatan a	
		INNER JOIN sk_jabatan b ON b.sk_id=a.sk_id
		WHERE TRIM(a.nama_jabatan) <>'-' 
		AND b.active='Y' 
		ORDER BY a.urut" ;
	$result = my_query($query);
	
	$row = array();
	while($ey = my_fetch_array($result) ){
		$datas = explode("," , $ey['kebutuhan_tenaga_kerja']);
		$totalgroup=$datas[0]+$datas[1]+$datas[2];
		$tersedia = getshifttersedia( $ey['jabatan_id'] );
		$kosong = ($totalgroup-$tersedia) ;
		$query = "SELECT count(*) AS total_data FROM jabatan_calon_karyawan
			WHERE jabatan_id = {$ey['jabatan_id']} ";
		$dres = my_query($query);
		$jumlah_kandidats= my_fetch_array($dres);
		$jumlah_kandidat=$jumlah_kandidats['total_data'];
		if($kosong>0){
			$i++; 
			if($jumlah_kandidat>0){
				$detailproperty = array(
					'href'=>'index.php?com=external_recruitment&task=detail&id='.$ey['jabatan_id'],
					'title'=>'Detail'
				);
				$detail_button = button_icon( 'b_props.png' , $detailproperty  );
			}else{
				$detail_button = button_icon( 'bd_deltbl.png' , ''  );		
			}	
			$row[] = array(
				'no'=>$i,			
				'nomor_org'=> $ey['nomor_posisi'],
				'jabatan'=>  $ey['nama_jabatan'] ,
				'kosong'=>$kosong,  
				'Kandidat'=>$jumlah_kandidat,  
				'operasi'=> position_text_align($detail_button , 'right'), 
			);	
		}	
	}
	$datas = table_rows($row);
	$menuontop = array(
		'Cetak' => array('onclick'=>'javascript:window.open(\'index.php?com=report&task=cetak_departemen\',\'mywin\',\'left=20,top=20,width=800,height=600,toolbar=0,resizable=0\');')
	);
	$printmenu = additional_menu_on_list( $menuontop ,'');
	return $printmenu.table_builder($header , $datas , 6, false );;
}

function list_kandidat($jabatan_id){
	$header  = array(
		'#'=>array('style'=>'border-bottom:2px solid;width:5%'), 
		'Calon Karyawan'=>array('style'=>'border-bottom:2px solid;width:95%'),  
	);
	$query = "SELECT karyawan_id FROM jabatan_calon_karyawan a
		WHERE jabatan_id = {$jabatan_id} ";
	$result = my_query($query);
	$i = 0;
	while($ey = my_fetch_array($result) ){
		$karyawan_id=$ey['karyawan_id'];
		$karyawan = loaddata_karyawan($karyawan_id);
		$i++;
		$row[] = array(
			'#'=>position_text_align ($i, 'center'),  
			'cakar'=>$karyawan[nama_gelar],
		);
	}
	$datas = table_rows($row);
	$jabatan = loaddata_jabatan($jabatan_id) ;
	$view .= form_header( "..." , "..."  );
	$view .= '<tr><td><td><div style="width:100%;text-align:right;">
	<input type="button" value="Back" class="main_button" onclick="javascript:location.href=\'index.php?com=external_recruitment\'"/>
	</div></td></tr>'   ; 
	$view .= form_field_display( '<span class="label_form">'.$jabatan['nomor_posisi'] .'</span>'  , "<b>Nomor Posisi</b>"    );  	
	$view .= form_field_display( '<span class="label_form">'.$jabatan['nama_jabatan'].'</span>'   , "<b>Jabatan</b>"    );  
	$view .= form_field_display( '<span class="label_form">'.$jabatan['organisasi_departemen'] .'</span>'  , "<b>Departemen</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.$jabatan['organisasi_direktorat'] .'</span>'  , "<b>Direktorat</b>"    ); 

	return  $view. table_builder($header , $datas ,  3 , false );
}
